package com.action;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mybatisplus.annotaion.AutoMapper;
import com.pojo.Student;
import com.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class StudentAction {

    @Autowired
    private StudentService studentService;

    @Autowired
    private AutoMapper  autoMapper;



    @RequestMapping("/")
    public String getAll(){
        List<Student> list = studentService.list();
        list.forEach((e)->{
            System.out.println(e.getId()+"\t"+e.getName()+"\t"+e.getClss().getName());
        });
        return "Hello,World";
    }

    @RequestMapping("/search")
    public List<Student> search(){
        //IPage<Student> result = studentService.search(new Page<Student>(1,10),"1班");
        IPage<Student> result = studentService.search(new Page<Student>(1,10),null,"2班");
        // 自定义sql则手动映射
        autoMapper.mapperEntityPage(result);
        return result.getRecords();
    }

}
